<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	积分、余额日志
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['adds']=array(
		'0'=>'消费',
		'1'=>'获得',
		'2'=>'提现',
);
$return['types2']=array(
		array('id'=>1,'title'=>'积分'),
		array('id'=>2,'title'=>'余额'),
);
$return['adds2']=array(
		array('id'=>0,'title'=>'消费'),
		array('id'=>1,'title'=>'获得'),
		array('id'=>2,'title'=>'提现'),
);
$return['types']=credit_types(true);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	$params=array('merchid'=>0,'uniacid'=>$_SESSION['uniacid'],'type'=>1,'plugin'=>'jy_area_jifee');
	$return['params']=array();
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//会员ID
	if(!empty($_RQ['tixian'])){
		$params['mid']=pdo_getcolumn('core_member_cash',array('id'=>$_RQ['id']),'mid');
		$return['params']['mid']=$params['mid'];
		$params['type']=2;
		$return['params']['type']=2;
	}
	//日志类型，1积分，2余额
	if(!empty($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	//日志种类，1增加，0减少
	if(isset($_RQ['is_add'])){
		$params['is_add']=intval($_RQ['is_add']);
		$return['params']['is_add']=$_RQ['is_add'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getslice('jy_merch_creditlog',$params,array($pindex,$psize),$total,array(),'','id desc');
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
		$item['plugin']=pdo_getcolumn('core_plugins',array('name'=>$item['plugin']),'title');
		$item['op_midname']=pdo_getcolumn('core_users',array('id'=>$item['op_mid']),'name');
		$item['op_midname']=$item['op_midname']?:'无';
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'积分余额记录'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'type','title'=>'积分类型','type'=>'radio','options'=>'types'),
			array('name'=>'is_add','title'=>'日志类型','type'=>'radio','options'=>'adds'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'plugin','title'=>'插件','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'op_midname','title'=>'操作员','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'select','width'=>15,'title'=>'日志类型','name'=>'is_add','options'=>'adds2'),
			array('type'=>'choose','width'=>15,'title'=>'会员id','name'=>'mid','action'=>'member.get_member','choose_title'=>'选择会员'),
			array('type'=>'time_range','width'=>18,'title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('merchid'=>0,'uniacid'=>$_SESSION['uniacid']);
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//会员ID
	if(!empty($_RQ['tixian'])){
		$params['mid']=pdo_getcolumn('core_member_cash',array('id'=>$_RQ['id']),'mid');
		$return['params']['mid']=$params['mid'];
		$params['type']=2;
		$return['params']['type']=2;
	}
	//日志类型，1积分，2余额
	if(!empty($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	//日志种类，1增加，0减少
	if(isset($_RQ['is_add'])){
		$params['is_add']=intval($_RQ['is_add']);
		$return['params']['is_add']=$_RQ['is_add'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('jy_merch_creditlog',$params);
	if($list){
		foreach($list as &$item){
			$member=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('username','nickname','avatar'));
			$item['nickname']=$member['nickname'];
			$item['username']=$member['username'];
			$item['status']=$item['status']==1?'已支付':'未支付';
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['is_add']=$return['adds'][$item['is_add']];
			$item['type']=$return['types'][$item['type']];
		}
	}
	$header=array(
		'mid'=>'ID',
		'username'=>'用户名称',
		'nickname'=>'用户昵称',
		'fee'=>'充值金额',
		'is_add'=>'消费/增加？',
		'type'=>'积分类型',
		'createtime'=>'时间',
	);
	cfc('tools')->export2excel($header,$list,'积分日志');
}